﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Harkon.AppServer.cOne.Service;
using Harkon.AppServer.cOne.Registry;
using System.Diagnostics;
using log4net;

namespace Harkon.AppServer.cOne.Deployment
{
    public class ServiceRegistryPerformer : AbstractService, ILifecycleAware
    {
        private static ILog logger = LogManager.GetLogger(typeof(ServiceRegistryPerformer));
        public IDictionary<string, IService> LocalServices { get; set; }

        public void RegisterServices()
        {
            foreach (var entry in LocalServices)
            {
                ServiceRegistry.RegisterService(entry.Value.Name, entry.Value);
            }   
        }

        #region ILifecycleAware Members

        public override bool Start()
        {
            if (base.Start())
            {
                logger.DebugFormat("ServiceRegistryPerformer starting");
                RegisterServices();
                return true;
            }
            return false;
        }

        #endregion
    }
}
